package com.ttt.controller;

import com.ttt.pojo.Course;
import com.ttt.service.SelectCourseCenterService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/FindCourse")
public class FindCourse extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("test/html;charset=utf-8");
        //获取前端数据
        String classType; //课程类型
        String academy; //开课学院
        String time; //上课时段
        String selectClassType = req.getParameter("selectClass");
        String selectAcademy = req.getParameter("selectAcademy");
        String selectTime = req.getParameter("selectTime");
        if (!selectClassType.isEmpty()){
            classType = selectClassType;
        }else {
            classType = null;
        }
        if (!selectAcademy.isEmpty()){
            academy = selectAcademy;
        }else {
            academy = null;
        }
        if (!selectTime.isEmpty()){
            time = selectTime;
        }else {
            time = null;
        }

        System.out.println("classType=" + classType + "academy=" + academy + "time=" + time);

        //调用service层代码
        SelectCourseCenterService selectCourseCenterService = new SelectCourseCenterService();
        try {
            List<Course> list = selectCourseCenterService.conditionFindCourse(classType, academy, time);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
}
